<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use App\Base\Annotation\Common;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ApiResource()
 * @ORM\Entity(repositoryClass="App\Repository\MoneyLogTypeRepository")
 */
class MoneyLogType
{
    /**
     * @Common(cnName="#",editType="text",listType="text",width="90")
     * @Groups({"app"})
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     * @Groups({"mlt"})
     */
    private $id;

    /**
     * @Common(cnName="名称",editType="text",listType="text",width="")
     * @Groups({"app"})
     * @ORM\Column(type="string", length=255)
     * @Groups({"mlt"})
     */
    private $name;

    /**
     * @ORM\OneToMany(targetEntity="App\Entity\MoneyLog", mappedBy="logType", orphanRemoval=true)
     */
    private $logs;

    /**
     * @Common(cnName="代码",editType="text",listType="text",width="")
     * @Groups({"app"})
     * @ORM\Column(type="integer")
     * @Groups({"mlt"})
     */
    private $code;

    public function __construct()
    {
        $this->logs = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    /**
     * @return Collection|MoneyLog[]
     */
    public function getLogs(): Collection
    {
        return $this->logs;
    }

    public function addLog(MoneyLog $log): self
    {
        if (!$this->logs->contains($log)) {
            $this->logs[] = $log;
            $log->setLogType($this);
        }

        return $this;
    }

    public function removeLog(MoneyLog $log): self
    {
        if ($this->logs->contains($log)) {
            $this->logs->removeElement($log);
            // set the owning side to null (unless already changed)
            if ($log->getLogType() === $this) {
                $log->setLogType(null);
            }
        }

        return $this;
    }

    public function getCode(): ?int
    {
        return $this->code;
    }

    public function setCode(int $code): self
    {
        $this->code = $code;

        return $this;
    }
}
